home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 December / maximum-cd-2009-12.iso / DiscContents / gimp-2.7.0-i686-setup.exe / {app} / share / gimp / 2.0 / scripts / addborder.scm < prev    next >
Encoding:
GIMP Script-Fu Script  |  2009-08-19  |  5.8 KB  |  186 lines

  1. ; GIMP - The GNU Image Manipulation Program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ;
  4. ; This program is free software: you can redistribute it and/or modify
  5. ; it under the terms of the GNU General Public License as published by
  6. ; the Free Software Foundation; either version 3 of the License, or
  7. ; (at your option) any later version.
  8. ;
  9. ; This program is distributed in the hope that it will be useful,
  10. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ; GNU General Public License for more details.
  13. ;
  14. ; You should have received a copy of the GNU General Public License
  15. ; along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16. ;
  17. ; Copyright (C) 1997 Andy Thomas alt@picnic.demon.co.uk
  18. ;
  19. ; Version 0.2 10.6.97 Changed to new script-fu interface in 0.99.10
  20.  
  21. ; Delta the colour by the given amount. Check for boundary conditions
  22. ; If < 0 set to zero
  23. ; If > 255 set to 255
  24. ; Return the new value
  25.  
  26. (define (script-fu-addborder aimg adraw xsize ysize colour dvalue)
  27.  
  28.   (define (deltacolour col delta)
  29.     (let* ((newcol (+ col delta)))
  30.       (if (< newcol 0) (set! newcol 0))
  31.       (if (> newcol 255) (set! newcol 255))
  32.       newcol
  33.     )
  34.   )
  35.  
  36.   (define (adjcolour col delta)
  37.     (mapcar (lambda (x) (deltacolour x delta)) col)
  38.   )
  39.  
  40.   (define (gen_top_array xsize ysize owidth oheight width height)
  41.     (let* ((n_array (cons-array 10 'double)))
  42.       (aset n_array 0 0 )
  43.       (aset n_array 1 0 )
  44.       (aset n_array 2 xsize)
  45.       (aset n_array 3 ysize)
  46.       (aset n_array 4 (+ xsize owidth))
  47.       (aset n_array 5 ysize)
  48.       (aset n_array 6 width)
  49.       (aset n_array 7 0 )
  50.       (aset n_array 8 0 )
  51.       (aset n_array 9 0 )
  52.       n_array)
  53.   )
  54.  
  55.   (define (gen_left_array xsize ysize owidth oheight width height)
  56.     (let* ((n_array (cons-array 10 'double)))
  57.       (aset n_array 0 0 )
  58.       (aset n_array 1 0 )
  59.       (aset n_array 2 xsize)
  60.       (aset n_array 3 ysize)
  61.       (aset n_array 4 xsize)
  62.       (aset n_array 5 (+ ysize oheight))
  63.       (aset n_array 6 0 )
  64.       (aset n_array 7 height )
  65.       (aset n_array 8 0 )
  66.       (aset n_array 9 0 )
  67.       n_array)
  68.   )
  69.  
  70.   (define (gen_right_array xsize ysize owidth oheight width height)
  71.     (let* ((n_array (cons-array 10 'double)))
  72.       (aset n_array 0 width )
  73.       (aset n_array 1 0 )
  74.       (aset n_array 2 (+ xsize owidth))
  75.       (aset n_array 3 ysize)
  76.       (aset n_array 4 (+ xsize owidth))
  77.       (aset n_array 5 (+ ysize oheight))
  78.       (aset n_array 6 width)
  79.       (aset n_array 7 height)
  80.       (aset n_array 8 width )
  81.       (aset n_array 9 0 )
  82.       n_array)
  83.   )
  84.  
  85.   (define (gen_bottom_array xsize ysize owidth oheight width height)
  86.     (let* ((n_array (cons-array 10 'double)))
  87.       (aset n_array 0 0 )
  88.       (aset n_array 1 height)
  89.       (aset n_array 2 xsize)
  90.       (aset n_array 3 (+ ysize oheight))
  91.       (aset n_array 4 (+ xsize owidth))
  92.       (aset n_array 5 (+ ysize oheight))
  93.       (aset n_array 6 width)
  94.       (aset n_array 7 height)
  95.       (aset n_array 8 0 )
  96.       (aset n_array 9 height)
  97.       n_array)
  98.   )
  99.  
  100.   (let* ((img (car (gimp-drawable-get-image adraw)))
  101.          (owidth (car (gimp-image-width img)))
  102.          (oheight (car (gimp-image-height img)))
  103.          (width (+ owidth (* 2 xsize)))
  104.          (height (+ oheight (* 2 ysize)))
  105.          (layer (car (gimp-layer-new img
  106.                                      width height
  107.                                      (car (gimp-drawable-type-with-alpha adraw))
  108.                                      "Border-Layer" 100 NORMAL-MODE))))
  109.  
  110.     (gimp-context-push)
  111.  
  112.     (gimp-image-undo-group-start img)
  113.  
  114.     (gimp-image-resize img
  115.                        width
  116.                        height
  117.                        xsize
  118.                        ysize)
  119.  
  120.     (gimp-image-add-layer img layer 0)
  121.     (gimp-drawable-fill layer TRANSPARENT-FILL)
  122.  
  123.     (gimp-context-set-background (adjcolour colour dvalue))
  124.     (gimp-free-select img
  125.                       10
  126.                       (gen_top_array xsize ysize owidth oheight width height)
  127.                       CHANNEL-OP-REPLACE
  128.                       0
  129.                       0
  130.                       0.0)
  131.     (gimp-edit-fill layer BACKGROUND-FILL)
  132.     (gimp-context-set-background (adjcolour colour (/ dvalue 2)))
  133.     (gimp-free-select img
  134.                       10
  135.                       (gen_left_array xsize ysize owidth oheight width height)
  136.                       CHANNEL-OP-REPLACE
  137.                       0
  138.                       0
  139.                       0.0)
  140.     (gimp-edit-fill layer BACKGROUND-FILL)
  141.     (gimp-context-set-background (adjcolour colour (- 0 (/ dvalue 2))))
  142.     (gimp-free-select img
  143.                       10
  144.                       (gen_right_array xsize ysize owidth oheight width height)
  145.                       CHANNEL-OP-REPLACE
  146.                       0
  147.                       0
  148.                       0.0)
  149.  
  150.     (gimp-edit-fill layer BACKGROUND-FILL)
  151.     (gimp-context-set-background (adjcolour colour (- 0 dvalue)))
  152.     (gimp-free-select img
  153.                       10
  154.                       (gen_bottom_array xsize ysize owidth oheight width height)
  155.                       CHANNEL-OP-REPLACE
  156.                       0
  157.                       0
  158.                       0.0)
  159.  
  160.     (gimp-edit-fill layer BACKGROUND-FILL)
  161.     (gimp-selection-none img)
  162.     (gimp-image-undo-group-end img)
  163.     (gimp-displays-flush)
  164.  
  165.     (gimp-context-pop)
  166.     )
  167. )
  168.  
  169. (script-fu-register "script-fu-addborder"
  170.   _"Add _Border..."
  171.   _"Add a border around an image"
  172.   "Andy Thomas <alt@picnic.demon.co.uk>"
  173.   "Andy Thomas"
  174.   "6/10/97"
  175.   "*"
  176.   SF-IMAGE       "Input image" 0
  177.   SF-DRAWABLE    "Input drawable" 0
  178.   SF-ADJUSTMENT _"Border X size" '(12 1 250 1 10 0 1)
  179.   SF-ADJUSTMENT _"Border Y size" '(12 1 250 1 10 0 1)
  180.   SF-COLOR      _"Border color" '(38 31 207)
  181.   SF-ADJUSTMENT _"Delta value on color" '(25 1 255 1 10 0 1)
  182. )
  183.  
  184. (script-fu-menu-register "script-fu-addborder"
  185.                          "<Image>/Filters/Decor")
  186.